package com.raidpoints.client;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Button;

public class ModSignupBox extends DialogBox {
	boolean acanceled;
	public ModSignupBox(final AccountPage map, final event mevt) {
		setHTML("Modify Signup");
		
		LayoutPanel layoutPanel = new LayoutPanel();
		setWidget(layoutPanel);
		layoutPanel.setSize("200px", "153px");
		
		final CheckBox cancelBox = new CheckBox("Cancel");
		layoutPanel.add(cancelBox);
		layoutPanel.setWidgetLeftWidth(cancelBox, 58.0, Unit.PX, 85.0, Unit.PX);
		layoutPanel.setWidgetTopHeight(cancelBox, 71.0, Unit.PX, 19.0, Unit.PX);
		
		final TextBox noteBox = new TextBox();
		layoutPanel.add(noteBox);
		noteBox.setWidth("145px");
		layoutPanel.setWidgetLeftWidth(noteBox, 15.0, Unit.PX, 165.0, Unit.PX);
		layoutPanel.setWidgetTopHeight(noteBox, 33.0, Unit.PX, 32.0, Unit.PX);
		
		Label lblNote = new Label("Note:");
		layoutPanel.add(lblNote);
		layoutPanel.setWidgetLeftWidth(lblNote, 15.0, Unit.PX, 56.0, Unit.PX);
		layoutPanel.setWidgetTopHeight(lblNote, 11.0, Unit.PX, 16.0, Unit.PX);
		
		Button updateButton = new Button("Update");
		layoutPanel.add(updateButton);
		layoutPanel.setWidgetLeftWidth(updateButton, 15.0, Unit.PX, 81.0, Unit.PX);
		layoutPanel.setWidgetTopHeight(updateButton, 108.0, Unit.PX, 28.0, Unit.PX);
		
		Button cancelButton = new Button("Cancel");
		layoutPanel.add(cancelButton);
		layoutPanel.setWidgetLeftWidth(cancelButton, 102.0, Unit.PX, 81.0, Unit.PX);
		layoutPanel.setWidgetTopHeight(cancelButton, 108.0, Unit.PX, 28.0, Unit.PX);
		
		acanceled = false;
		if(mevt.mynote != null) noteBox.setText(mevt.mynote);
		if(mevt.canceled) {cancelBox.setValue(true); acanceled = true;}
		
		cancelButton.addClickHandler(new ClickHandler(){
			@Override
			public void onClick(ClickEvent event) {
				hide();
			}
		});
		
		final AsyncCallback<String> updateCallback = new AsyncCallback<String>(){

			@Override
			public void onFailure(Throwable caught) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onSuccess(String result) {
				map.Refresh();				
			}
			
		};
		
		updateButton.addClickHandler(new ClickHandler(){
			@Override
			public void onClick(ClickEvent event) {
				if(cancelBox.getValue()) mevt.canceled = true;
				else mevt.canceled = false;
				//else if(acanceled) mevt.attend = "signedup";
				mevt.mynote = noteBox.getText();
				map.rp.rpsvc.ModifySignup(mevt, updateCallback);
				hide();
			}
		});
	}
}
